﻿namespace TestTool.Tests.Common.Transport
{
    using System;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Xml;
    using TestTool.HttpTransport.Interfaces;

    public class WsaController : IWsaController, ITransportController, IChannelController
    {
        private UniqueId _messageId;
        private Uri _replyTo;

        public void ProcessRequest(Message message)
        {
            this._messageId = message.Headers.MessageId;
            message.Headers.ReplyTo = new EndpointAddress("http://www.w3.org/2005/08/addressing/anonymous");
            this._replyTo = message.Headers.ReplyTo.Uri;
        }

        public void Validate(Message message)
        {
            if (!message.IsFault && string.IsNullOrEmpty(message.Headers.Action))
            {
                throw new ApplicationException("WS-Addressing \"Action\" header is missing");
            }
        }
    }
}

